classdef ET_DEM < ET_ANALYSIS
    
    
    methods 
        
        function self = ET_DEM(edfFileInstance)
           self = self@ET_ANALYSIS(edfFileInstance); 
        end
        
        function occluderVector = occluderVector(self,signal)
           % Returns a function which occludes the target
           right =  (self.occluder.X +  self.occluder.W/2)  ;
           left =  (self.occluder.X - self.occluder.W/2) ;

           right = self.angle(right+self.scn.w/2);
           left = self.angle(left+self.scn.w/2);
           occluderVector = (signal > min(right,left)).*(signal < max(right,left));
           
        end
        
        function [signals s v ] = cellSignals(self)
            
            v = self.returnVectors(1,100);
            s = self.edffile.signal();
            s = edffile.interpolateSignal(s,'spline');
            s = edffile.filter(s,20,1000);
            s = s(1:10:end);
            
            s = self.angle(s);
            v = self.angle(v);
            occluderV = self.occluderVector(v);
            mt = min(numel(s),numel(v));
            s = s(:);
            v = v(:);
            occluderV = occluderV(:);

            signals = exp(-(kron(ones(mt,1),-8:8) - kron(ones(1,17),s(1:mt) - v(1:mt))).^2).*~kron(ones(1,17),occluderV(1:mt)); 
        end
        
        function g = g_function(self)

            right =  self.occluder.X + self.occluder.W/2;
            left =  self.occluder.X - self.occluder.W/2;
            right = self.angle(right+self.scn.w/2);
            left = self.angle(left+self.scn.w/2);
            
            right = sprintf('%0.4f',right);
            left = sprintf('%0.4f',left);

            g = ['[x.o(1); exp(-([-8:8]'' - x.x + x.o(1)).^2)*~((x.x >' ...
                'min(' right ',' left  ')).*(x.x <' 'max(' right ',' left  ')))]'];
            %g = ['[x.o; exp(-([-8:8]'' - x.x + x.o(1)).^2)]'];            
        end
        
        function azimuth = angle(self,s)
            azimuth = atan(((s - self.scn.w/2)*(self.scn.wcm/self.scn.w))...
                /self.view_dist) *(180/pi);
        end
    end
    
    properties 
       
        DEM 
        
    end
        
        
end